<!DOCTYPE html>
<html lang=zh>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  <meta name="google-site-verification" content="XKEVBvaS3n3qpVoP-hQqQ2XJ9t43pt4B7J1sLZgRJG4" />
  
  
  <title>源码分析 | PostgreSQL 回归测试详解 | DBKernel - 专注于分享数据库技术</title>
  <meta name="description" content="本文首发于 2016-03-30 15:29:35  背景回归测试是 PostgreSQL 的测试方法之一。 回归测试，需要事先定义好测试脚本（通常是 SQL 脚本，放在 sql 目录中），同时定义好调用执行测试脚本的预期正确输出文件（通常放在 expected 目录中)。 测试使用 make check 或 make installcheck 进行，它会通过 pg_regress 程序调用">
<meta property="og:type" content="article">
<meta property="og:title" content="源码分析 | PostgreSQL 回归测试详解">
<meta property="og:url" content="http://dbkernel.github.io/2016/03/30/postgresql-regression-test-details/index.html">
<meta property="og:site_name" content="DBKernel">
<meta property="og:description" content="本文首发于 2016-03-30 15:29:35  背景回归测试是 PostgreSQL 的测试方法之一。 回归测试，需要事先定义好测试脚本（通常是 SQL 脚本，放在 sql 目录中），同时定义好调用执行测试脚本的预期正确输出文件（通常放在 expected 目录中)。 测试使用 make check 或 make installcheck 进行，它会通过 pg_regress 程序调用">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://dbkernel-1306518848.cos.ap-beijing.myqcloud.com/wechat/my-wechat-official-account.png">
<meta property="article:published_time" content="2016-03-30T07:29:35.000Z">
<meta property="article:modified_time" content="2021-09-22T15:24:33.492Z">
<meta property="article:author" content="DBKernel">
<meta property="article:tag" content="源码分析">
<meta property="article:tag" content="PostgreSQL">
<meta property="article:tag" content="回归测试">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://dbkernel-1306518848.cos.ap-beijing.myqcloud.com/wechat/my-wechat-official-account.png">
  <!-- Canonical links -->
  <link rel="canonical" href="http://dbkernel.github.io/2016/03/30/postgresql-regression-test-details/index.html">
  
    <link rel="alternate" href="/atom.xml" title="DBKernel" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  
<link rel="stylesheet" href="../../../../css/style.css">

  
  
  
  
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1.4.0/dist/gitalk.min.css">
  
<meta name="generator" content="Hexo 5.4.0"></head>


<body class="main-center" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://github.com/dbkernel" target="_blank">
          <img class="img-circle img-rotate" src="../../../../images/avatar.png" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">DBKernel</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">资深数据库开发工程师</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Beijing, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav ">
        
        
        <li class="menu-item menu-item-home">
          <a href="../../../../.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="../../../../archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="../../../../categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="../../../../tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-repository">
          <a href="../../../../repository">
            
            <i class="icon icon-project"></i>
            
            <span class="menu-title">项目</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-links">
          <a href="../../../../links">
            
            <i class="icon icon-friendship"></i>
            
            <span class="menu-title">友链</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="../../../../about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="../../../../https:/github.com/dbkernel" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="../../../../atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>本站专注于分享关系型数据库及分布式数据库相关技术！如需深入交流，可添加我的微信或关注我的公众号数据库内核：</br><img src="/images/wechat-me.jpeg" width="130" height="130"/> <img src="/images/wechat-gzh.jpeg" width="130" height="130"/></p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="../../../../categories/ClickHouse/">ClickHouse</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/C%E8%AF%AD%E8%A8%80/">C语言</a><span class="category-list-count">8</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/GreenPlum/">GreenPlum</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/Linux/">Linux</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/MySQL/">MySQL</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/PostgreSQL/">PostgreSQL</a><span class="category-list-count">7</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/Postgres-X2/">Postgres-X2</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/%E7%BC%96%E8%AF%91%E8%B0%83%E8%AF%95/">编译调试</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="../../../../categories/%E9%80%9A%E7%94%A8/">通用</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/APUE/" rel="tag">APUE</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/B-Tree/" rel="tag">B-Tree</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/ClickHouse/" rel="tag">ClickHouse</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/ClickHouse%E5%92%8C%E4%BB%96%E7%9A%84%E6%9C%8B%E5%8F%8B%E4%BB%AC/" rel="tag">ClickHouse和他的朋友们</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Count/" rel="tag">Count</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/C%E8%AF%AD%E8%A8%80/" rel="tag">C语言</a><span class="tag-list-count">10</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/DAG-Scheduler/" rel="tag">DAG Scheduler</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/GreenPlum/" rel="tag">GreenPlum</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/HEAP%E5%BC%95%E6%93%8E/" rel="tag">HEAP引擎</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/LICENCE/" rel="tag">LICENCE</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/LSM-Tree/" rel="tag">LSM-Tree</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Linux/" rel="tag">Linux</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/MEMORY%E5%BC%95%E6%93%8E/" rel="tag">MEMORY引擎</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Makefile/" rel="tag">Makefile</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Materialized-View/" rel="tag">Materialized View</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/MergeTree/" rel="tag">MergeTree</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/MySQL/" rel="tag">MySQL</a><span class="tag-list-count">8</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Parser/" rel="tag">Parser</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Percona/" rel="tag">Percona</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/PostgreSQL/" rel="tag">PostgreSQL</a><span class="tag-list-count">11</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Postgres-X2/" rel="tag">Postgres-X2</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Postgres-XC/" rel="tag">Postgres-XC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/RadonDB/" rel="tag">RadonDB</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/ReplicatedMergeTree/" rel="tag">ReplicatedMergeTree</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Select/" rel="tag">Select</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/UNIX/" rel="tag">UNIX</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/WAL/" rel="tag">WAL</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Xenon/" rel="tag">Xenon</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Xtrabackup/" rel="tag">Xtrabackup</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/auto-increment/" rel="tag">auto_increment</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/crontab/" rel="tag">crontab</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/daemon/" rel="tag">daemon</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/df/" rel="tag">df</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/du/" rel="tag">du</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/gcc/" rel="tag">gcc</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/gcov/" rel="tag">gcov</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/getopt/" rel="tag">getopt</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/github/" rel="tag">github</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/group-by/" rel="tag">group by</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/lcov/" rel="tag">lcov</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/libpq/" rel="tag">libpq</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/pg-constraint/" rel="tag">pg_constraint</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/pg-depend/" rel="tag">pg_depend</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/pgbench/" rel="tag">pgbench</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/pipeline/" rel="tag">pipeline</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/processor/" rel="tag">processor</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/shell/" rel="tag">shell</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/" rel="tag">主从同步</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E4%BC%98%E5%8C%96%E5%99%A8/" rel="tag">优化器</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%86%85%E5%AD%98%E5%88%86%E9%85%8D/" rel="tag">内存分配</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/" rel="tag">内存管理</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%9B%9E%E5%BD%92%E6%B5%8B%E8%AF%95/" rel="tag">回归测试</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%AD%97%E8%8A%82%E5%AF%B9%E9%BD%90/" rel="tag">字节对齐</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%AD%97%E8%8A%82%E5%BA%8F/" rel="tag">字节序</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%AD%98%E5%82%A8%E8%AE%A1%E7%AE%97%E5%88%86%E7%A6%BB/" rel="tag">存储计算分离</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%B9%B6%E8%A1%8C%E6%9F%A5%E8%AF%A2/" rel="tag">并行查询</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%BC%80%E6%BA%90%E5%8D%8F%E8%AE%AE/" rel="tag">开源协议</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E5%BC%80%E6%BA%90%E8%AE%B8%E5%8F%AF%E8%AF%81/" rel="tag">开源许可证</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E6%9C%AC%E5%9C%B0%E4%BA%8B%E5%8A%A1/" rel="tag">本地事务</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E6%B5%8B%E8%AF%95/" rel="tag">测试</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90/" rel="tag">源码分析</a><span class="tag-list-count">15</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4/" rel="tag">系统运维</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E7%BC%96%E8%AF%91%E5%99%A8/" rel="tag">编译器</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E7%BD%91%E7%BB%9C%E5%BA%8F/" rel="tag">网络序</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/" rel="tag">网络编程</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/%E9%97%AE%E9%A2%98%E5%AE%9A%E4%BD%8D/" rel="tag">问题定位</a><span class="tag-list-count">2</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="../../../../tags/APUE/" style="font-size: 13.33px;">APUE</a> <a href="../../../../tags/B-Tree/" style="font-size: 13px;">B-Tree</a> <a href="../../../../tags/ClickHouse/" style="font-size: 13.89px;">ClickHouse</a> <a href="../../../../tags/ClickHouse%E5%92%8C%E4%BB%96%E7%9A%84%E6%9C%8B%E5%8F%8B%E4%BB%AC/" style="font-size: 13.89px;">ClickHouse和他的朋友们</a> <a href="../../../../tags/Count/" style="font-size: 13px;">Count</a> <a href="../../../../tags/C%E8%AF%AD%E8%A8%80/" style="font-size: 13.67px;">C语言</a> <a href="../../../../tags/DAG-Scheduler/" style="font-size: 13px;">DAG Scheduler</a> <a href="../../../../tags/GreenPlum/" style="font-size: 13.22px;">GreenPlum</a> <a href="../../../../tags/HEAP%E5%BC%95%E6%93%8E/" style="font-size: 13px;">HEAP引擎</a> <a href="../../../../tags/LICENCE/" style="font-size: 13px;">LICENCE</a> <a href="../../../../tags/LSM-Tree/" style="font-size: 13px;">LSM-Tree</a> <a href="../../../../tags/Linux/" style="font-size: 13.44px;">Linux</a> <a href="../../../../tags/MEMORY%E5%BC%95%E6%93%8E/" style="font-size: 13px;">MEMORY引擎</a> <a href="../../../../tags/Makefile/" style="font-size: 13px;">Makefile</a> <a href="../../../../tags/Materialized-View/" style="font-size: 13px;">Materialized View</a> <a href="../../../../tags/MergeTree/" style="font-size: 13.11px;">MergeTree</a> <a href="../../../../tags/MySQL/" style="font-size: 13.56px;">MySQL</a> <a href="../../../../tags/Parser/" style="font-size: 13px;">Parser</a> <a href="../../../../tags/Percona/" style="font-size: 13px;">Percona</a> <a href="../../../../tags/PostgreSQL/" style="font-size: 13.78px;">PostgreSQL</a> <a href="../../../../tags/Postgres-X2/" style="font-size: 13px;">Postgres-X2</a> <a href="../../../../tags/Postgres-XC/" style="font-size: 13px;">Postgres-XC</a> <a href="../../../../tags/RadonDB/" style="font-size: 13px;">RadonDB</a> <a href="../../../../tags/ReplicatedMergeTree/" style="font-size: 13px;">ReplicatedMergeTree</a> <a href="../../../../tags/Select/" style="font-size: 13px;">Select</a> <a href="../../../../tags/UNIX/" style="font-size: 13.22px;">UNIX</a> <a href="../../../../tags/WAL/" style="font-size: 13.11px;">WAL</a> <a href="../../../../tags/Xenon/" style="font-size: 13px;">Xenon</a> <a href="../../../../tags/Xtrabackup/" style="font-size: 13px;">Xtrabackup</a> <a href="../../../../tags/auto-increment/" style="font-size: 13px;">auto_increment</a> <a href="../../../../tags/crontab/" style="font-size: 13px;">crontab</a> <a href="../../../../tags/daemon/" style="font-size: 13px;">daemon</a> <a href="../../../../tags/df/" style="font-size: 13px;">df</a> <a href="../../../../tags/du/" style="font-size: 13px;">du</a> <a href="../../../../tags/gcc/" style="font-size: 13px;">gcc</a> <a href="../../../../tags/gcov/" style="font-size: 13px;">gcov</a> <a href="../../../../tags/getopt/" style="font-size: 13px;">getopt</a> <a href="../../../../tags/github/" style="font-size: 13px;">github</a> <a href="../../../../tags/group-by/" style="font-size: 13px;">group by</a> <a href="../../../../tags/lcov/" style="font-size: 13px;">lcov</a> <a href="../../../../tags/libpq/" style="font-size: 13px;">libpq</a> <a href="../../../../tags/pg-constraint/" style="font-size: 13px;">pg_constraint</a> <a href="../../../../tags/pg-depend/" style="font-size: 13px;">pg_depend</a> <a href="../../../../tags/pgbench/" style="font-size: 13px;">pgbench</a> <a href="../../../../tags/pipeline/" style="font-size: 13px;">pipeline</a> <a href="../../../../tags/processor/" style="font-size: 13px;">processor</a> <a href="../../../../tags/shell/" style="font-size: 13px;">shell</a> <a href="../../../../tags/%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5/" style="font-size: 13.11px;">主从同步</a> <a href="../../../../tags/%E4%BC%98%E5%8C%96%E5%99%A8/" style="font-size: 13px;">优化器</a> <a href="../../../../tags/%E5%86%85%E5%AD%98%E5%88%86%E9%85%8D/" style="font-size: 13px;">内存分配</a> <a href="../../../../tags/%E5%86%85%E5%AD%98%E7%AE%A1%E7%90%86/" style="font-size: 13px;">内存管理</a> <a href="../../../../tags/%E5%9B%9E%E5%BD%92%E6%B5%8B%E8%AF%95/" style="font-size: 13px;">回归测试</a> <a href="../../../../tags/%E5%AD%97%E8%8A%82%E5%AF%B9%E9%BD%90/" style="font-size: 13.11px;">字节对齐</a> <a href="../../../../tags/%E5%AD%97%E8%8A%82%E5%BA%8F/" style="font-size: 13.11px;">字节序</a> <a href="../../../../tags/%E5%AD%98%E5%82%A8%E8%AE%A1%E7%AE%97%E5%88%86%E7%A6%BB/" style="font-size: 13px;">存储计算分离</a> <a href="../../../../tags/%E5%B9%B6%E8%A1%8C%E6%9F%A5%E8%AF%A2/" style="font-size: 13px;">并行查询</a> <a href="../../../../tags/%E5%BC%80%E6%BA%90%E5%8D%8F%E8%AE%AE/" style="font-size: 13px;">开源协议</a> <a href="../../../../tags/%E5%BC%80%E6%BA%90%E8%AE%B8%E5%8F%AF%E8%AF%81/" style="font-size: 13px;">开源许可证</a> <a href="../../../../tags/%E6%9C%AC%E5%9C%B0%E4%BA%8B%E5%8A%A1/" style="font-size: 13px;">本地事务</a> <a href="../../../../tags/%E6%B5%8B%E8%AF%95/" style="font-size: 13px;">测试</a> <a href="../../../../tags/%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90/" style="font-size: 14px;">源码分析</a> <a href="../../../../tags/%E7%B3%BB%E7%BB%9F%E8%BF%90%E7%BB%B4/" style="font-size: 13px;">系统运维</a> <a href="../../../../tags/%E7%BC%96%E8%AF%91%E5%99%A8/" style="font-size: 13px;">编译器</a> <a href="../../../../tags/%E7%BD%91%E7%BB%9C%E5%BA%8F/" style="font-size: 13.11px;">网络序</a> <a href="../../../../tags/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/" style="font-size: 13px;">网络编程</a> <a href="../../../../tags/%E9%97%AE%E9%A2%98%E5%AE%9A%E4%BD%8D/" style="font-size: 13.11px;">问题定位</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2021/08/">八月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2021/01/">一月 2021</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2020/09/">九月 2020</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2020/08/">八月 2020</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2020/07/">七月 2020</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2020/06/">六月 2020</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2020/05/">五月 2020</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2019/12/">十二月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2019/04/">四月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2018/09/">九月 2018</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2016/11/">十一月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2016/04/">四月 2016</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2016/03/">三月 2016</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2016/01/">一月 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2015/12/">十二月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2015/11/">十一月 2015</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2015/05/">五月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2015/01/">一月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2014/08/">八月 2014</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2014/07/">七月 2014</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2014/03/">三月 2014</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="../../../../archives/2014/01/">一月 2014</a><span class="archive-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="../../../../categories/%E9%80%9A%E7%94%A8/">通用</a>
              </p>
              <p class="item-title">
                <a href="../../../../2021/08/19/how-to-choose-open-source-licence/" class="title">技术分享 | 如何为你的代码选择一个合适的开源协议？</a>
              </p>
              <p class="item-date">
                <time datetime="2021-08-18T16:37:15.000Z" itemprop="datePublished">2021-08-19</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="../../../../categories/ClickHouse/">ClickHouse</a>
              </p>
              <p class="item-title">
                <a href="../../../../2021/01/26/clickhouse-and-friends-15-groupby/" class="title">源码分析 | ClickHouse和他的朋友们（15）Group By 为什么这么快</a>
              </p>
              <p class="item-date">
                <time datetime="2021-01-26T13:31:12.000Z" itemprop="datePublished">2021-01-26</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="../../../../categories/ClickHouse/">ClickHouse</a>
              </p>
              <p class="item-title">
                <a href="../../../../2020/09/21/clickhouse-and-friends-14-compute-storage/" class="title">源码分析 | ClickHouse和他的朋友们（14）存储计算分离方案与实现</a>
              </p>
              <p class="item-date">
                <time datetime="2020-09-21T14:01:12.000Z" itemprop="datePublished">2020-09-21</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="../../../../categories/ClickHouse/">ClickHouse</a>
              </p>
              <p class="item-title">
                <a href="../../../../2020/09/15/clickhouse-and-friends-13-replicated-merge-tree/" class="title">源码分析 | ClickHouse和他的朋友们（13）ReplicatedMergeTree表引擎及同步机制</a>
              </p>
              <p class="item-date">
                <time datetime="2020-09-15T12:15:14.000Z" itemprop="datePublished">2020-09-15</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="../../../../categories/ClickHouse/">ClickHouse</a>
              </p>
              <p class="item-title">
                <a href="../../../../2020/09/03/clickhouse-and-friends-12-materialized-view/" class="title">源码分析 | ClickHouse和他的朋友们（12）神奇的物化视图(Materialized View)与原理</a>
              </p>
              <p class="item-date">
                <time datetime="2020-09-03T13:22:14.000Z" itemprop="datePublished">2020-09-03</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%83%8C%E6%99%AF"><span class="toc-number">1.</span> <span class="toc-text">背景</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9B%9E%E5%BD%92%E6%B5%8B%E8%AF%95%E7%94%A8%E6%B3%95"><span class="toc-number">2.</span> <span class="toc-text">回归测试用法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%82%E8%80%83"><span class="toc-number">3.</span> <span class="toc-text">参考</span></a></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-postgresql-regression-test-details" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      源码分析 | PostgreSQL 回归测试详解
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="" class="article-date">
	  <time datetime="2016-03-30T07:29:35.000Z" itemprop="datePublished">2016-03-30</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="../../../../categories/PostgreSQL/">PostgreSQL</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link-link" href="../../../../tags/PostgreSQL/" rel="tag">PostgreSQL</a>, <a class="article-tag-link-link" href="../../../../tags/%E5%9B%9E%E5%BD%92%E6%B5%8B%E8%AF%95/" rel="tag">回归测试</a>, <a class="article-tag-link-link" href="../../../../tags/%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90/" rel="tag">源码分析</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


        <span class="post-comment"><i class="icon icon-comment"></i> <a href="#comments" class="article-comment-link">评论</a></span>
        
	
		<span class="post-wordcount hidden-xs" itemprop="wordCount">字数统计: 3.6k(字)</span>
	
	
		<span class="post-readcount hidden-xs" itemprop="timeRequired">阅读时长: 18(分)</span>
	

      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <span id="more"></span>

<blockquote>
<p><strong>本文首发于 2016-03-30 15:29:35</strong></p>
</blockquote>
<h2 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h2><p>回归测试是 PostgreSQL 的测试方法之一。</p>
<p>回归测试，需要事先定义好测试脚本（通常是 SQL 脚本，放在 sql 目录中），同时定义好调用执行测试脚本的预期正确输出文件（通常放在 expected 目录中)。</p>
<p>测试使用 <code>make check</code> 或 <code>make installcheck</code> 进行，它会通过 <code>pg_regress</code> 程序调用 sql 目录中的 SQL，并收集输出结果（通常放到 results 目录中），最后 pg_regress 会对 expected 目录和 results 目录中的文件使用 diff 进行一一比较。</p>
<p>如果比较发现文件内容不一致，会将不一致的结果输出到 <code>regression.diffs</code> 文件中，并返回这个 TEST CASE failed。</p>
<p>但是这种测试方法实际上有一些需要注意的地方，例如我们使用不同的本地化设置，时区可能得到的结果和期望的结果就不一样。另外有些不可预知的结果，例如随机值，数据的顺序，执行计划和优化器相关参数有关。这些因素都可能导致测试结果和预期不一致，那么我们就需要人为去修复这种 failed。</p>
<p>PostgreSQL 的主代码测试文件在 <code>src/test/regress</code> 目录中。</p>
<p>这个目录的结构如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">postgres@digoal-&gt; ll -rt</span><br><span class="line">total 1.2M</span><br><span class="line">-rw-r--r-- 1 postgres postgres  579 Jun 10 03:29 standby_schedule <span class="comment"># 测试standby的调度配置, 其实就是调度sql里的文件名</span></span><br><span class="line">-rw-r--r-- 1 postgres postgres 2.3K Jun 10 03:29 serial_schedule <span class="comment"># 串行测试的调度配置</span></span><br><span class="line">-rw-r--r-- 1 postgres postgres  937 Jun 10 03:29 resultmap <span class="comment"># 不同的测试平台的结果映射文件，因为不同平台某些测试结果可能不相同，所以一个expected文件不能支持所有的平台。例如浮点数测试。</span></span><br><span class="line">-rwxr-xr-x 1 postgres postgres 4.4K Jun 10 03:29 regressplans.sh</span><br><span class="line">-rw-r--r-- 1 postgres postgres  20K Jun 10 03:29 regress.c</span><br><span class="line">-rw-r--r-- 1 postgres postgres  159 Jun 10 03:29 README</span><br><span class="line">-rw-r--r-- 1 postgres postgres 2.7K Jun 10 03:29 pg_regress_main.c</span><br><span class="line">-rw-r--r-- 1 postgres postgres 1.6K Jun 10 03:29 pg_regress.h</span><br><span class="line">-rw-r--r-- 1 postgres postgres  69K Jun 10 03:29 pg_regress.c</span><br><span class="line">-rw-r--r-- 1 postgres postgres 3.6K Jun 10 03:29 parallel_schedule <span class="comment"># 并行测试的调度配置</span></span><br><span class="line">-rw-r--r-- 1 postgres postgres  624 Jun 10 03:29 Makefile</span><br><span class="line">-rw-r--r-- 1 postgres postgres 5.6K Jun 10 03:29 GNUmakefile</span><br><span class="line">drwxrwxrwx 2 postgres postgres 4.0K Jun 10 03:38 output</span><br><span class="line">drwxrwxrwx 2 postgres postgres 4.0K Jun 10 03:38 input</span><br><span class="line">drwxrwxrwx 2 postgres postgres 4.0K Jun 10 03:38 data   一些测试数据</span><br><span class="line">drwxrwxrwx 2 postgres postgres 4.0K Sep  7 14:51 sql <span class="comment"># 测试用到的SQL</span></span><br><span class="line">drwxrwxr-x 2 postgres postgres 4.0K Sep  7 14:52 results <span class="comment"># 通过pg_regress调用sql目录中的脚本，得到的结果</span></span><br><span class="line">drwxrwxrwx 2 postgres postgres 4.0K Sep  7 14:51 expected <span class="comment"># 执行sql目录中的文件对应的正确返回结果</span></span><br></pre></td></tr></table></figure>

<p>上层目录结构如下，其中包含了一些其他的测试目标，例如隔离级别的测试，本地化测试，性能测试，线程安全测试。等。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">postgres@digoal-&gt; <span class="built_in">cd</span> /opt/soft_bak/postgresql-9.4.4/src/<span class="built_in">test</span></span><br><span class="line">postgres@digoal-&gt; ll</span><br><span class="line">total 36K</span><br><span class="line">drwxrwxrwx  2 postgres postgres 4.0K Jun 10 03:38 examples</span><br><span class="line">drwxrwxrwx  4 postgres postgres 4.0K Jun 10 03:41 isolation</span><br><span class="line">drwxrwxrwx  6 postgres postgres 4.0K Jun 10 03:38 locale</span><br><span class="line">-rw-r--r--  1 postgres postgres  389 Jun 10 03:29 Makefile</span><br><span class="line">drwxrwxrwx  4 postgres postgres 4.0K Jun 10 03:38 mb</span><br><span class="line">drwxrwxrwx  4 postgres postgres 4.0K Jun 10 03:38 performance</span><br><span class="line">drwxrwxrwx  2 postgres postgres 4.0K Jun 10 03:38 perl</span><br><span class="line">drwxrwxrwx 10 postgres postgres 4.0K Sep  7 19:17 regress</span><br><span class="line">drwxrwxrwx  2 postgres postgres 4.0K Jun 10 03:38 thread</span><br></pre></td></tr></table></figure>

<p>接下来我们看看 PostgreSQL 的回归测试程序 pg_regress 的用法，它不会安装到 PGHOME/bin 中，只在 src/test/regress 中存在。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">cd</span> src/<span class="built_in">test</span>/regress</span><br><span class="line">$ src/<span class="built_in">test</span>/regress/pg_regress --<span class="built_in">help</span></span><br><span class="line">PostgreSQL regression <span class="built_in">test</span> driver</span><br><span class="line"></span><br><span class="line">Usage:</span><br><span class="line">  pg_regress [OPTION]... [EXTRA-TEST]...</span><br><span class="line"></span><br><span class="line">Options:</span><br><span class="line">  --config-auth=DATADIR     update authentication settings <span class="keyword">for</span> DATADIR</span><br><span class="line">  --create-role=ROLE        create the specified role before testing</span><br><span class="line">  --dbname=DB               use database DB (default <span class="string">&quot;regression&quot;</span>)</span><br><span class="line">  --debug                   turn on debug mode <span class="keyword">in</span> programs that are run</span><br><span class="line">  --dlpath=DIR              look <span class="keyword">for</span> dynamic libraries <span class="keyword">in</span> DIR</span><br><span class="line">  --encoding=ENCODING       use ENCODING as the encoding</span><br><span class="line">  --inputdir=DIR            take input files from DIR (default <span class="string">&quot;.&quot;</span>)</span><br><span class="line">  --launcher=CMD            use CMD as launcher of psql</span><br><span class="line">  --load-extension=EXT      load the named extension before running the</span><br><span class="line">                            tests; can appear multiple <span class="built_in">times</span></span><br><span class="line">  --load-language=LANG      load the named language before running the</span><br><span class="line">                            tests; can appear multiple <span class="built_in">times</span></span><br><span class="line">  --max-connections=N       maximum number of concurrent connections</span><br><span class="line">                            (default is 0, meaning unlimited)</span><br><span class="line">  --outputdir=DIR           place output files <span class="keyword">in</span> DIR (default <span class="string">&quot;.&quot;</span>)</span><br><span class="line">  --schedule=FILE           use <span class="built_in">test</span> ordering schedule from FILE</span><br><span class="line">                            (can be used multiple <span class="built_in">times</span> to concatenate)</span><br><span class="line">  --temp-install=DIR        create a temporary installation <span class="keyword">in</span> DIR</span><br><span class="line">  --use-existing            use an existing installation</span><br><span class="line"></span><br><span class="line">Options <span class="keyword">for</span> <span class="string">&quot;temp-install&quot;</span> mode:</span><br><span class="line">  --extra-install=DIR       additional directory to install (e.g., contrib)</span><br><span class="line">  --no-locale               use C locale</span><br><span class="line">  --port=PORT               start postmaster on PORT</span><br><span class="line">  --temp-config=FILE        append contents of FILE to temporary config</span><br><span class="line">  --top-builddir=DIR        (relative) path to top level build directory</span><br><span class="line"></span><br><span class="line">Options <span class="keyword">for</span> using an existing installation:</span><br><span class="line">  --host=HOST               use postmaster running on HOST</span><br><span class="line">  --port=PORT               use postmaster running at PORT</span><br><span class="line">  --user=USER               connect as USER</span><br><span class="line">  --psqldir=DIR             use psql <span class="keyword">in</span> DIR (default: configured bindir)</span><br><span class="line"></span><br><span class="line">The <span class="built_in">exit</span> status is 0 <span class="keyword">if</span> all tests passed, 1 <span class="keyword">if</span> some tests failed, and 2</span><br><span class="line"><span class="keyword">if</span> the tests could not be run <span class="keyword">for</span> some reason.</span><br><span class="line"></span><br><span class="line">Report bugs to &lt;pgsql-bugs@postgresql.org&gt;.</span><br></pre></td></tr></table></figure>

<h2 id="回归测试用法"><a href="#回归测试用法" class="headerlink" title="回归测试用法"></a>回归测试用法</h2><p>在 PostgreSQL 源码根目录，或者源码的 regress 目录中执行如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">make check <span class="comment"># 测试时需要初始化数据库集群</span></span><br><span class="line">make installcheck <span class="comment"># 使用以及启动的数据库集群测试，不需要初始化数据库集群</span></span><br></pre></td></tr></table></figure>

<p>以下同时测试主代码以及 contrib 的代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">make check-world</span><br><span class="line">make installcheck-world</span><br></pre></td></tr></table></figure>

<p>如果要使用自定义的 diff 参数，可以设置一个环境变量，例如：<code>make check PG_REGRESS_DIFF_OPTS=&#39;-u&#39;</code>。</p>
<p>同时我们还可以使用不同的 LOCALE 进行测试。例如：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">make check LANG=de_DE.utf8</span><br><span class="line">make check NO_LOCALE=1</span><br><span class="line">make check LANG=C ENCODING=EUC_JP</span><br></pre></td></tr></table></figure>

<p>当我们要测试调度中不包含的测试 SQL 时，可以使用 <code>EXTRA_TESTS</code> 参数，至于这些脚本为什么默认不包含在调度中，可能是因为这些 SQL 脚本可能对平台的依赖比较严重，所以没有放到默认的测试中。例如：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">make check EXTRA_TESTS=collate.linux.utf8 LANG=en_US.utf8</span><br><span class="line">make check EXTRA_TESTS=numeric_big</span><br></pre></td></tr></table></figure>

<p>接下来我们看看调度文件以及 sql 脚本目录：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">postgres@digoal-&gt; <span class="built_in">pwd</span></span><br><span class="line">/opt/soft_bak/postgresql-9.4.4/src/<span class="built_in">test</span>/regress</span><br><span class="line">postgres@digoal-&gt; less serial_schedule</span><br><span class="line"><span class="comment"># src/test/regress/serial_schedule</span></span><br><span class="line"><span class="comment"># This should probably be in an order similar to parallel_schedule.</span></span><br><span class="line"><span class="built_in">test</span>: tablespace</span><br><span class="line"><span class="built_in">test</span>: boolean</span><br><span class="line"><span class="built_in">test</span>: char</span><br><span class="line"><span class="built_in">test</span>: name</span><br><span class="line"><span class="built_in">test</span>: varchar</span><br><span class="line"><span class="built_in">test</span>: text</span><br><span class="line"><span class="built_in">test</span>: int2</span><br><span class="line"><span class="built_in">test</span>: int4</span><br><span class="line"><span class="built_in">test</span>: int8</span><br><span class="line">......</span><br></pre></td></tr></table></figure>

<p>并行调度：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">postgres@digoal-&gt; less parallel_schedule</span><br><span class="line"><span class="comment"># ----------</span></span><br><span class="line"><span class="comment"># src/test/regress/parallel_schedule</span></span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># By convention, we put no more than twenty tests in any one parallel group;</span></span><br><span class="line"><span class="comment"># this limits the number of connections needed to run the tests.</span></span><br><span class="line"><span class="comment"># ----------</span></span><br><span class="line"><span class="comment"># run tablespace by itself, and first, because it forces a checkpoint;</span></span><br><span class="line"><span class="comment"># we&#x27;d prefer not to have checkpoints later in the tests because that</span></span><br><span class="line"><span class="comment"># interferes with crash-recovery testing.</span></span><br><span class="line"><span class="built_in">test</span>: tablespace</span><br><span class="line"></span><br><span class="line"><span class="comment"># ----------</span></span><br><span class="line"><span class="comment"># The first group of parallel tests</span></span><br><span class="line"><span class="comment"># ----------</span></span><br><span class="line"><span class="built_in">test</span>: boolean char name varchar text int2 int4 int8 oid float4 float8 bit numeric txid uuid enum money rangetypes pg_lsn regproc</span><br><span class="line">......</span><br></pre></td></tr></table></figure>

<p>调度文件的 test: 后面跟的就是sql目录下的文件名(不含 .sql 后缀)。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">postgres@digoal-&gt; less sql/</span><br><span class="line">total 1940</span><br><span class="line">drwxrwxrwx  2 postgres postgres   4096 Sep  7 14:51 ./</span><br><span class="line">drwxrwxrwx 10 postgres postgres   4096 Sep  7 22:34 ../</span><br><span class="line">-rw-r--r--  1 postgres postgres   2237 Jun 10 03:29 abstime.sql</span><br><span class="line">-rw-r--r--  1 postgres postgres   4097 Jun 10 03:29 advisory_lock.sql</span><br><span class="line">-rw-r--r--  1 postgres postgres  20295 Jun 10 03:29 aggregates.sql</span><br><span class="line">-rw-r--r--  1 postgres postgres  24882 Jun 10 03:29 alter_generic.sql</span><br><span class="line">-rw-r--r--  1 postgres postgres  54461 Jun 10 03:29 alter_table.sql</span><br><span class="line">-rw-r--r--  1 postgres postgres  17244 Jun 10 03:29 arrays.sql</span><br><span class="line">-rw-r--r--  1 postgres postgres    594 Jun 10 03:29 async.sql</span><br><span class="line">-rw-r--r--  1 postgres postgres   1365 Jun 10 03:29 bitmapops.sql</span><br><span class="line">-rw-r--r--  1 postgres postgres   6406 Jun 10 03:29 bit.sql</span><br><span class="line">-rw-r--r--  1 postgres postgres   4164 Jun 10 03:29 boolean.sql</span><br><span class="line">......</span><br></pre></td></tr></table></figure>

<p>所以前面提到的 EXTRA_TESTS 实际上也是 sql 目录中的文件名(不带 .sql 后缀)。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">make check EXTRA_TESTS=collate.linux.utf8 LANG=en_US.utf8</span><br><span class="line">make check EXTRA_TESTS=numeric_big</span><br></pre></td></tr></table></figure>

<p>来实际的试一下吧：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line">postgres@digoal-&gt; <span class="built_in">pwd</span></span><br><span class="line">/opt/soft_bak/postgresql-9.4.4/src/<span class="built_in">test</span>/regress</span><br><span class="line">postgres@digoal-&gt; make installcheck-parallel  //并行测试，使用已经开启的现有的数据库集群</span><br><span class="line">make -C ../../../src/port all</span><br><span class="line">......</span><br><span class="line">../../../src/<span class="built_in">test</span>/regress/pg_regress --inputdir=. --psqldir=<span class="string">&#x27;/opt/pgsql9.4.4/bin&#x27;</span>    --dlpath=.  --schedule=./parallel_schedule</span><br><span class="line">(using postmaster on /data01/pg_root_1921, port 1921)</span><br><span class="line">============== dropping database <span class="string">&quot;regression&quot;</span>         ==============</span><br><span class="line">DROP DATABASE</span><br><span class="line">============== creating database <span class="string">&quot;regression&quot;</span>         ==============</span><br><span class="line">CREATE DATABASE</span><br><span class="line">ALTER DATABASE</span><br><span class="line">============== running regression <span class="built_in">test</span> queries        ==============</span><br><span class="line"><span class="built_in">test</span> tablespace               ... ok</span><br><span class="line">......</span><br><span class="line">parallel group (19 tests):  <span class="built_in">limit</span> conversion sequence returning without_oid polymorphism copy2 xml prepare plancache rowtypes temp domain with truncate largeobject rangefuncs alter_table plpgsql</span><br><span class="line">     plancache                ... ok</span><br><span class="line">     <span class="built_in">limit</span>                    ... ok</span><br><span class="line">     plpgsql                  ... ok</span><br><span class="line">     copy2                    ... ok</span><br><span class="line">     temp                     ... ok</span><br><span class="line">     domain                   ... ok</span><br><span class="line">     rangefuncs               ... FAILED</span><br><span class="line">     prepare                  ... ok</span><br><span class="line">     without_oid              ... ok</span><br><span class="line">     conversion               ... ok</span><br><span class="line">     truncate                 ... ok</span><br><span class="line">     alter_table              ... ok</span><br><span class="line">     sequence                 ... ok</span><br><span class="line">     polymorphism             ... FAILED</span><br><span class="line">     rowtypes                 ... ok</span><br><span class="line">     returning                ... ok</span><br><span class="line">     largeobject              ... ok</span><br><span class="line">     with                     ... FAILED</span><br><span class="line">     xml                      ... ok</span><br><span class="line"><span class="built_in">test</span> stats                    ... ok</span><br><span class="line">......</span><br><span class="line">=========================</span><br><span class="line"> 22 of 145 tests failed.</span><br><span class="line">=========================</span><br><span class="line"></span><br><span class="line">The differences that caused some tests to fail can be viewed <span class="keyword">in</span> the</span><br><span class="line">file <span class="string">&quot;/opt/soft_bak/postgresql-9.4.4/src/test/regress/regression.diffs&quot;</span>.  A copy of the <span class="built_in">test</span> summary that you see</span><br><span class="line">above is saved <span class="keyword">in</span> the file <span class="string">&quot;/opt/soft_bak/postgresql-9.4.4/src/test/regress/regression.out&quot;</span>.</span><br><span class="line"></span><br><span class="line">make: *** [installcheck-parallel] Error 1</span><br></pre></td></tr></table></figure>

<p>有些测试失败了，diff 文件已经输出到 <code>/opt/soft_bak/postgresql-9.4.4/src/test/regress/regression.diffs</code>，我们可以查看一下看看为什么测试结果和预期结果不一致。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">postgres@digoal-&gt; less regression.diffs</span><br><span class="line">*** /opt/soft_bak/postgresql-9.4.4/src/<span class="built_in">test</span>/regress/expected/pg_lsn.out 2015-06-10 03:29:38.000000000 +0800</span><br><span class="line">--- /opt/soft_bak/postgresql-9.4.4/src/<span class="built_in">test</span>/regress/results/pg_lsn.out  2015-09-07 22:45:04.413922536 +0800</span><br><span class="line">***************</span><br><span class="line">*** 72,92 ****</span><br><span class="line">         generate_series(1, 5) k</span><br><span class="line">    WHERE i &lt;= 10 AND j &gt; 0 AND j &lt;= 10</span><br><span class="line">    ORDER BY f;</span><br><span class="line">!                                 QUERY PLAN</span><br><span class="line">! --------------------------------------------------------------------------</span><br><span class="line">!  Sort</span><br><span class="line">!    Sort Key: (((((i.i)::text || <span class="string">&#x27;/&#x27;</span>::text) || (j.j)::text))::pg_lsn)</span><br><span class="line">!    -&gt;  HashAggregate</span><br><span class="line">!          Group Key: ((((i.i)::text || <span class="string">&#x27;/&#x27;</span>::text) || (j.j)::text))::pg_lsn</span><br><span class="line">           -&gt;  Nested Loop</span><br><span class="line">                 -&gt;  Function Scan on generate_series k</span><br><span class="line">!                -&gt;  Materialize</span><br><span class="line">!                      -&gt;  Nested Loop</span><br><span class="line">!                            -&gt;  Function Scan on generate_series j</span><br><span class="line">!                                  Filter: ((j &gt; 0) AND (j &lt;= 10))</span><br><span class="line">!                            -&gt;  Function Scan on generate_series i</span><br><span class="line">!                                  Filter: (i &lt;= 10)</span><br><span class="line">! (12 rows)</span><br><span class="line"></span><br><span class="line">  SELECT DISTINCT (i || <span class="string">&#x27;/&#x27;</span> || j)::pg_lsn f</span><br><span class="line">    FROM generate_series(1, 10) i,</span><br><span class="line">--- 72,90 ----</span><br><span class="line">         generate_series(1, 5) k</span><br><span class="line">    WHERE i &lt;= 10 AND j &gt; 0 AND j &lt;= 10</span><br><span class="line">    ORDER BY f;</span><br><span class="line">......</span><br></pre></td></tr></table></figure>

<p>对于主代码，如果我们需要自定义测试 SQL，我们可以修改 <code>regress/sql</code> 目录下的文件，或者新增文件。同时修改 <code>regress/expected</code> 目录下的对应期望文件，或者现在期望文件。</p>
<p>如果是新增文件的情况，我们还需要修改调度文件 <code>regress/serial_schedule和regress/parallel_schedule</code>，把测试加入调度。</p>
<p>最后，再以 <code>ltree</code> 插件为例，看看如何配置一个外加插件的回归测试。</p>
<p>ltree 的源码目录：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">postgres@digoal-&gt; <span class="built_in">cd</span> contrib/</span><br><span class="line">postgres@digoal-&gt; <span class="built_in">cd</span> ltree/</span><br><span class="line">postgres@digoal-&gt; ll -rt</span><br><span class="line">total 1.1M</span><br><span class="line">-rw-r--r-- 1 postgres postgres  517 Jun 10 03:29 Makefile</span><br><span class="line">-rw-r--r-- 1 postgres postgres 2.4K Jun 10 03:29 ltxtquery_op.c</span><br><span class="line">-rw-r--r-- 1 postgres postgres  11K Jun 10 03:29 ltxtquery_io.c</span><br><span class="line">-rw-r--r-- 1 postgres postgres 7.9K Jun 10 03:29 ltree--unpackaged--1.0.sql</span><br><span class="line">-rw-r--r-- 1 postgres postgres  994 Jun 10 03:29 ltreetest.sql</span><br><span class="line">-rw-r--r-- 1 postgres postgres  13K Jun 10 03:29 ltree_op.c</span><br><span class="line">-rw-r--r-- 1 postgres postgres 6.9K Jun 10 03:29 _ltree_op.c</span><br><span class="line">-rw-r--r-- 1 postgres postgres  14K Jun 10 03:29 ltree_io.c</span><br><span class="line">-rw-r--r-- 1 postgres postgres 7.3K Jun 10 03:29 ltree.h</span><br><span class="line">-rw-r--r-- 1 postgres postgres  16K Jun 10 03:29 ltree_gist.c</span><br><span class="line">-rw-r--r-- 1 postgres postgres  13K Jun 10 03:29 _ltree_gist.c</span><br><span class="line">-rw-r--r-- 1 postgres postgres  155 Jun 10 03:29 ltree.control</span><br><span class="line">-rw-r--r-- 1 postgres postgres  18K Jun 10 03:29 ltree--1.0.sql</span><br><span class="line">-rw-r--r-- 1 postgres postgres 7.1K Jun 10 03:29 lquery_op.c</span><br><span class="line">-rw-r--r-- 1 postgres postgres  263 Jun 10 03:29 crc32.h</span><br><span class="line">-rw-r--r-- 1 postgres postgres 4.1K Jun 10 03:29 crc32.c</span><br><span class="line">drwxrwxrwx 2 postgres postgres 4.0K Jun 10 03:38 sql</span><br><span class="line">drwxrwxrwx 2 postgres postgres 4.0K Jun 10 03:38 expected</span><br><span class="line">drwxrwxrwx 2 postgres postgres 4.0K Jun 10 03:38 data</span><br></pre></td></tr></table></figure>

<p>contrib/ltree 的 Makefile 如下（在这里配置回归测试的调度，用到变量 REGRESS，对应 sql 目录中的脚本文件名）：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># contrib/ltree/Makefile</span></span><br><span class="line"></span><br><span class="line">MODULE_big = ltree</span><br><span class="line">OBJS =  ltree_io.o ltree_op.o lquery_op.o _ltree_op.o crc32.o \</span><br><span class="line">        ltxtquery_io.o ltxtquery_op.o ltree_gist.o _ltree_gist.o</span><br><span class="line">PG_CPPFLAGS = -DLOWER_NODE</span><br><span class="line"></span><br><span class="line">EXTENSION = ltree</span><br><span class="line">DATA = ltree--1.0.sql ltree--unpackaged--1.0.sql</span><br><span class="line"></span><br><span class="line">REGRESS = ltree</span><br><span class="line"></span><br><span class="line">ifdef USE_PGXS</span><br><span class="line">PG_CONFIG = pg_config</span><br><span class="line">PGXS := $(shell $(PG_CONFIG) --pgxs)</span><br><span class="line">include $(PGXS)</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">subdir = contrib/ltree</span><br><span class="line">top_builddir = ../..</span><br><span class="line">include $(top_builddir)/src/Makefile.global</span><br><span class="line">include $(top_srcdir)/contrib/contrib-global.mk</span><br><span class="line">endif</span><br></pre></td></tr></table></figure>

<p>其中：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">include $(PGXS)</span><br></pre></td></tr></table></figure>

<p>或：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">include $(top_builddir)/src/Makefile.global</span><br></pre></td></tr></table></figure>

<p>都指向了：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">src/makefiles/pgxs.mk</span><br></pre></td></tr></table></figure>

<p>这个 makefile 中会用到回归测试相关的两个变量：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#   REGRESS -- list of regression test cases (without suffix)</span></span><br><span class="line"><span class="comment">#   REGRESS_OPTS -- additional switches to pass to pg_regress</span></span><br></pre></td></tr></table></figure>

<p>引用 <code>src/makefiles/pgxs.mk</code> 的部分内容如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line">ifdef REGRESS</span><br><span class="line"></span><br><span class="line"><span class="comment"># Select database to use for running the tests</span></span><br><span class="line">ifneq ($(USE_MODULE_DB),)</span><br><span class="line">  REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB_MODULE)</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">  REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB)</span><br><span class="line">endif</span><br><span class="line"></span><br><span class="line"><span class="comment"># where to find psql for running the tests</span></span><br><span class="line">PSQLDIR = $(bindir)</span><br><span class="line"></span><br><span class="line"><span class="comment"># When doing a VPATH build, must copy over the data files so that the</span></span><br><span class="line"><span class="comment"># driver script can find them.  We have to use an absolute path for</span></span><br><span class="line"><span class="comment"># the targets, because otherwise make will try to locate the missing</span></span><br><span class="line"><span class="comment"># files using VPATH, and will find them in $(srcdir), but the point</span></span><br><span class="line"><span class="comment"># here is that we want to copy them from $(srcdir) to the build</span></span><br><span class="line"><span class="comment"># directory.</span></span><br><span class="line"></span><br><span class="line">ifdef VPATH</span><br><span class="line">abs_builddir := $(shell <span class="built_in">pwd</span>)</span><br><span class="line">test_files_src := $(wildcard $(srcdir)/data/*.data)</span><br><span class="line">test_files_build := $(patsubst $(srcdir)/%, $(abs_builddir)/%, $(test_files_src))</span><br><span class="line"></span><br><span class="line">all: $(test_files_build)</span><br><span class="line">$(test_files_build): $(abs_builddir)/%: $(srcdir)/%</span><br><span class="line">        $(MKDIR_P) $(dir <span class="variable">$@</span>)</span><br><span class="line">        ln -s $&lt; <span class="variable">$@</span></span><br><span class="line">endif <span class="comment"># VPATH</span></span><br><span class="line"></span><br><span class="line">.PHONY: submake</span><br><span class="line">submake:</span><br><span class="line">ifndef PGXS</span><br><span class="line">        $(MAKE) -C $(top_builddir)/src/<span class="built_in">test</span>/regress pg_regress$(X)</span><br><span class="line">endif</span><br><span class="line"></span><br><span class="line"><span class="comment"># against installed postmaster</span></span><br><span class="line">installcheck: submake $(REGRESS_PREP)</span><br><span class="line">        $(pg_regress_installcheck) $(REGRESS_OPTS) $(REGRESS)</span><br><span class="line"></span><br><span class="line">ifdef PGXS</span><br><span class="line">check:</span><br><span class="line">        @<span class="built_in">echo</span> <span class="string">&#x27;&quot;$(MAKE) check&quot; is not supported.&#x27;</span></span><br><span class="line">        @<span class="built_in">echo</span> <span class="string">&#x27;Do &quot;$(MAKE) install&quot;, then &quot;$(MAKE) installcheck&quot; instead.&#x27;</span></span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">check: all submake $(REGRESS_PREP)</span><br><span class="line">        $(pg_regress_check) --extra-install=$(subdir) $(REGRESS_OPTS) $(REGRESS)</span><br><span class="line">endif</span><br><span class="line">endif <span class="comment"># REGRESS</span></span><br></pre></td></tr></table></figure>

<p>这里用到了 ltree 中 Makefile 中定义的 subdir 和 REGRESS 变量，如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">top_builddir = ../..</span><br><span class="line">subdir = contrib/ltree</span><br><span class="line">REGRESS = ltree</span><br></pre></td></tr></table></figure>

<p>所以我们在 contrib/ltree 中执行 make check 会执行：(指PGXS未定义时)</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$(pg_regress_check) --extra-install=$(subdir) $(REGRESS_OPTS) $(REGRESS)</span><br></pre></td></tr></table></figure>

<p>pg_regress_check 这个变量在 <code>src/Makefile.global</code> 中定义了，其实就是 pg_regress 命令的调用：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">src/Makefile.global</span><br><span class="line">src/Makefile.global:srcdir = .</span><br><span class="line">pg_regress_locale_flags = $(<span class="keyword">if</span> $(ENCODING),--encoding=$(ENCODING)) $(NOLOCALE)</span><br><span class="line">pg_regress_check = $(top_builddir)/src/<span class="built_in">test</span>/regress/pg_regress --inputdir=$(srcdir) --temp-install=./tmp_check --top-builddir=$(top_builddir) $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)</span><br></pre></td></tr></table></figure>

<p>在 contrib/ltree 中执行 make check 最终执行的是(没有定义的变量直接忽略)：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">../../src/<span class="built_in">test</span>/regress/pg_regress --inputdir=. --temp-install=./tmp_check --top-builddir=../.. --extra-install=contrib/ltree ltree</span><br></pre></td></tr></table></figure>

<p>我们可以直接到 ltree 的源码目录测试这条命令：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">[root@digoal ~]<span class="comment"># chown -R postgres:postgres /opt/soft_bak/postgresql-9.4.4</span></span><br><span class="line">[root@digoal ~]<span class="comment"># su - postgres</span></span><br><span class="line">postgres@digoal-&gt; <span class="built_in">cd</span> /opt/soft_bak/postgresql-9.4.4/contrib/ltree/</span><br><span class="line">postgres@digoal-&gt; ../../src/<span class="built_in">test</span>/regress/pg_regress --inputdir=. --temp-install=./tmp_check --top-builddir=../.. --extra-install=contrib/ltree ltree</span><br><span class="line">============== removing existing temp installation    ==============</span><br><span class="line">============== creating temporary installation        ==============</span><br><span class="line">============== initializing database system           ==============</span><br><span class="line">============== starting postmaster                    ==============</span><br><span class="line">running on port 57636 with PID 27852</span><br><span class="line">============== creating database <span class="string">&quot;regression&quot;</span>         ==============</span><br><span class="line">CREATE DATABASE</span><br><span class="line">ALTER DATABASE</span><br><span class="line">============== running regression <span class="built_in">test</span> queries        ==============</span><br><span class="line"><span class="built_in">test</span> ltree                    ... ok</span><br><span class="line">============== shutting down postmaster               ==============</span><br><span class="line">============== removing temporary installation        ==============</span><br><span class="line"></span><br><span class="line">=====================</span><br><span class="line"> All 1 tests passed.</span><br><span class="line">=====================</span><br></pre></td></tr></table></figure>

<p>另外一种测试时 installcheck，和 check 不同的是，installcheck 不需要初始化数据库，是在我们开启了数据库集群的情况下的测试。</p>
<p>同样的方法，我们可以发现它调用的是：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$(pg_regress_installcheck) $(REGRESS_OPTS) $(REGRESS)</span><br></pre></td></tr></table></figure>

<p>通过 src/Makefile.global 的定义：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pg_regress_installcheck = $(top_builddir)/src/<span class="built_in">test</span>/regress/pg_regress --inputdir=$(srcdir) --psqldir=<span class="string">&#x27;$(PSQLDIR)&#x27;</span> $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)</span><br><span class="line">bindir := $(shell $(PG_CONFIG) --bindir)</span><br></pre></td></tr></table></figure>

<p>以及 src/makefiles/pgxs.mk</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">PSQLDIR = $(bindir)</span><br></pre></td></tr></table></figure>

<p>最终转换为：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">../../src/<span class="built_in">test</span>/regress/pg_regress --inputdir=. --psqldir=<span class="string">&#x27;/opt/pgsql/bin&#x27;</span> ltree</span><br></pre></td></tr></table></figure>

<p>启动数据库后，就可以进行测试了。同样需要注意(PGPORT PGHOST PGDATABASE PGUSER 等)环境变量。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">postgres@digoal-&gt; pg_ctl start</span><br><span class="line">postgres@digoal-&gt; <span class="built_in">pwd</span></span><br><span class="line">/opt/soft_bak/postgresql-9.4.4/contrib/ltree</span><br><span class="line">postgres@digoal-&gt; ../../src/<span class="built_in">test</span>/regress/pg_regress --inputdir=. --psqldir=<span class="string">&#x27;/opt/pgsql/bin&#x27;</span> ltree</span><br><span class="line">(using postmaster on /data01/pg_root_1921, port 1921)</span><br><span class="line">============== dropping database <span class="string">&quot;regression&quot;</span>         ==============</span><br><span class="line">DROP DATABASE</span><br><span class="line">============== creating database <span class="string">&quot;regression&quot;</span>         ==============</span><br><span class="line">CREATE DATABASE</span><br><span class="line">ALTER DATABASE</span><br><span class="line">============== running regression <span class="built_in">test</span> queries        ==============</span><br><span class="line"><span class="built_in">test</span> ltree                    ... ok</span><br><span class="line"></span><br><span class="line">=====================</span><br><span class="line"> All 1 tests passed.</span><br><span class="line">=====================</span><br></pre></td></tr></table></figure>

<p>所以插件的回归测试配置也很简单，同样需要 sql, expected 目录，以及通过配置 Makefile 来指定需要回归测试的 sql 脚本。</p>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><ol>
<li><a target="_blank" rel="noopener" href="http://www.postgresql.org/docs/devel/static/regress-run.html">http://www.postgresql.org/docs/devel/static/regress-run.html</a></li>
<li><a target="_blank" rel="noopener" href="http://www.postgresql.org/docs/devel/static/regress-variant.html">http://www.postgresql.org/docs/devel/static/regress-variant.html</a></li>
</ol>
<p>各种Makefile</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">src/Makefile.global</span><br><span class="line">src/Makefile</span><br><span class="line">src/makefiles/pgxs.mk</span><br><span class="line">contrib/contrib-global.mk</span><br><span class="line">contrib/xx/Makefile</span><br><span class="line">......</span><br></pre></td></tr></table></figure>

<blockquote>
<p>本文转自：<a target="_blank" rel="noopener" href="https://github.com/digoal/blog/blob/master/201509/20150907_04.md">https://github.com/digoal/blog/blob/master/201509/20150907_04.md</a></p>
</blockquote>
<hr>
<p>欢迎关注我的微信公众号【数据库内核】：分享主流开源数据库和存储引擎相关技术。</p>
<img src="https://dbkernel-1306518848.cos.ap-beijing.myqcloud.com/wechat/my-wechat-official-account.png" width="400" height="400" alt="欢迎关注公众号数据库内核" align="center"/>


<table>
<thead>
<tr>
<th>标题</th>
<th>网址</th>
</tr>
</thead>
<tbody><tr>
<td>GitHub</td>
<td><a href="https://dbkernel.github.io/">https://dbkernel.github.io</a></td>
</tr>
<tr>
<td>知乎</td>
<td><a target="_blank" rel="noopener" href="https://www.zhihu.com/people/dbkernel/posts">https://www.zhihu.com/people/dbkernel/posts</a></td>
</tr>
<tr>
<td>思否（SegmentFault）</td>
<td><a target="_blank" rel="noopener" href="https://segmentfault.com/u/dbkernel">https://segmentfault.com/u/dbkernel</a></td>
</tr>
<tr>
<td>掘金</td>
<td><a target="_blank" rel="noopener" href="https://juejin.im/user/5e9d3ed251882538083fed1f/posts">https://juejin.im/user/5e9d3ed251882538083fed1f/posts</a></td>
</tr>
<tr>
<td>开源中国（oschina）</td>
<td><a target="_blank" rel="noopener" href="https://my.oschina.net/dbkernel">https://my.oschina.net/dbkernel</a></td>
</tr>
<tr>
<td>博客园（cnblogs）</td>
<td><a target="_blank" rel="noopener" href="https://www.cnblogs.com/dbkernel">https://www.cnblogs.com/dbkernel</a></td>
</tr>
</tbody></table>

      
    </div>
    <div class="article-footer">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://dbkernel.github.io/2016/03/30/postgresql-regression-test-details/" title="源码分析 | PostgreSQL 回归测试详解" target="_blank" rel="external">http://dbkernel.github.io/2016/03/30/postgresql-regression-test-details/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN 许可协议</a>，转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://github.com/dbkernel" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="../../../../images/avatar.png" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://github.com/dbkernel" target="_blank"><span class="text-dark">DBKernel</span><small class="ml-1x">资深数据库开发工程师</small></a></h3>
        <div>目前从事云数据库MySQL/PostgreSQL的研发工作，曾做过PGXC、Greenplum等分布式数据库的内核开发。热衷于研究主流数据库架构、源码，对关系型数据库 MySQL/PostgreSQL及分布式数据库有深入研究。</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
           
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="../test-postgresql-code-coverage-using-gcov-and-lcov/" title="源码分析 | 使用 gcov 和 lcov 测试 PostgreSQL 代码覆盖率"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="../../15/how-to-install-postgres-xc-on-linux/" title="最佳实践 | 源码编译安装配置 Postgres-XC 集群并用 pg_basebackup 配置 Datanode 热备"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-fancy btn-donate pop-onhover bg-gradient-warning" data-toggle="modal" data-target="#donateModal"><span>赏</span></button>
  <!-- <div class="wave-icon wave-icon-danger btn-donate" data-toggle="modal" data-target="#donateModal">
    <div class="wave-circle"><span class="icon"><i class="icon icon-bill"></i></span></div>
  </div> -->
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,qzone,facebook,twitter,linkedin" data-mobile-sites="weibo,qq,wechat,qzone,linkedin"></div>
    
  </div>
  </div>
</nav>
  
<!-- Modal -->
<div class="modal modal-center modal-small modal-xs-full fade" id="donateModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content donate">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <div class="modal-body">
        <div class="donate-box">
          <div class="donate-head">
            <p>感谢您的支持，我会继续努力的!</p>
          </div>
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane fade active in" id="alipay">
              <div class="donate-payimg">
                <img src="../../../../images/donate/alipayimg.png" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开支付宝扫一扫，即可进行扫码打赏哦</p>
            </div>
            <div role="tabpanel" class="tab-pane fade" id="wechatpay">
              <div class="donate-payimg">
                <img src="../../../../images/donate/wechatpayimg.png" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开微信扫一扫，即可进行扫码打赏哦</p>
            </div>
          </div>
          <div class="donate-footer">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <li role="presentation" class="active">
                <a href="#alipay" id="alipay-tab" role="tab" data-toggle="tab" aria-controls="alipay" aria-expanded="true"><i class="icon icon-alipay"></i> 支付宝</a>
              </li>
              <li role="presentation" class="">
                <a href="#wechatpay" role="tab" id="wechatpay-tab" data-toggle="tab" aria-controls="wechatpay" aria-expanded="false"><i class="icon icon-wepay"></i> 微信支付</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>



</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="../../../../https:/github.com/dbkernel" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="../../../../atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        &copy; 2022 DBKernel
        
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="../../../../js/plugin.min.js"></script>


<script src="../../../../js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '../../../../content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="../../../../js/insight.js"></script>






   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





   
    
  <!-- <link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css"> -->
  <script src="//cdn.jsdelivr.net/npm/gitalk@1.4.0/dist/gitalk.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/blueimp-md5@2.10.0/js/md5.min.js"></script>
  <script type="text/javascript">
  var gitalk = new Gitalk({
    clientID: '642675de9efee853bde8',
    clientSecret: 'e481d901d83ac31b4041437ec30a4fd00d112cfa',
    repo: 'dbkernel/gitalk-comment',
    owner: 'dbkernel',
    admin: ['dbkernel1989'],
    id: md5(location.pathname),
    distractionFreeMode: true
  })
  gitalk.render('comments')
  </script>

      






    <script defer>
var _hmt = _hmt || [];
(function() {
    var hm = document.createElement("script");
    hm.src = "//hm.baidu.com/hm.js?bf7f972e25b6a36ff4b828ba0214e515";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();
</script>



</body>
</html>